package models

type Member struct {
	Model
	Name string `json:"name"`
	Link string `json:"link"`
	Job string `json:"job"`
	Graduate int8 `json:"graduate"`
	Company string `json:"company"`
	ImgUrl string `json:"img_url"`
	Direction string `json:"direction"`
}

func ExistMemberByID(id int) bool {
	var member Member
	db.Select("id").Where("id = ?", id).First(&member)
	return member.ID > 0
}

func GetMembers(maps interface{}) (members []Member) {
	db.Where(maps).Find(&members)
	return
}

func GetMembersTotal(maps interface{}) (count int) {
	db.Model(&Member{}).Where(maps).Count(&count)
	return
}

func AddMember(name, link, job, imgUrl, direction string) bool {
	db.Create(&Member{
		Name: name,
		Link: link,
		Job: job,
		ImgUrl: imgUrl,
		Direction: direction,
	})
	return true
}

func DeleteMember(id int) bool {
	db.Where("id = ?", id).Delete(&Member{})
	return true
}

func UpdateMember(id int, data interface{}) bool {
	db.Model(&Member{}).Where("id = ?", id).Updates(data)
	return true
}